Skip to content


tag  jupyter  tips  ai  deep learning  beginner  regression  ardupilot  None  ros2  dds  micro ros  xrce  sitl  plugin  SITL  debug  rangefinder  pymavlink  mavros  gazebo  distance sensor  system_time  timesync  cmake  gtest  ctest  101  cpp  c++  format  fmt  multithreading  spdlog  cyclonedds  eprosima  fastdds  simulation  config  ignition  bridge  sdf  ign-transport  camera  sensors  lidar  aptly  apt  repository  repo  local  mirror  encryption  pgp  docker  nvidia  python  app  devcontainer  gui  multi-stage  stage  git  bundle  submodules  github  hooks  pre-commit  lxd  container  lxc  x11  profile  vscode  marpit  presentation  marp  markdown  mermaid  mkdocs  video  ffmpeg  gstreamer  cheat-sheet  sdp  v4l2loopback  gi  kml  geo  gis  spatial  gdal  ogr  raster  vector  snippets  cheat Sheet  asyncio  future  click  cli  deb  debian  package  setup  stdeb  project  numpy  template  black  isort  templates  cookiecutter  docs  project document  docstrings  flake8  linter  git-hook  mypy  unittest  pytest  pylint  from a-z  mock  iterator  generator  logging  tuple  namedtuple  typing  annotation  typever  pyzmq  zmq  msgpack  action  namespace  remap  control2  ros2_control  effort  velocity  gdb  qos  plugins  msg  node  zero-copy  shm  tutorial  algorithm  calibration  diff  pid  dev  colcon  colcon_cd  rpi  arm  qemu  settings  behavior  py_trees  bt  behavior_trees  blackboard  plot  visualization  debugging  diagnostic  DiagnosticTask  diagnostics  tutorials  gst  math  apm  rat_runtime_monitor  web  rosbridge  vue  binding  discovery  gazebo-classic  launch  spawn  model  cook  gps  imu  ray  gazebo_ros_ray_sensor  ultrsonic  range  ultrasonic  gazebo classic  wrench  odom  ign  gz  xacro  ros_ign  diff_drive  odometry  joint_state  argument  OpaqueFunction  DeclareLaunchArgument  LaunchConfiguration  tmux  nav  slam  test  rclpy  goal abort  cancel goal  action client  action server  custom messages  executor  MultiThreadedExecutor  SingleThreadedExecutor  param  dynamic-reconfigure  service  client  setup.py  package.xml  parameter  parameters  custom  msgs  executers  pub  sub  rqt  rviz  rviz2  pose  marker  tf2  local_setup  rosdep  package manager  project settings  vcstool  urdf  robot_state_publisher  urdf_to_graphiz  joint  link  cross-compiler  nano  texture  joints  tmuxp  loop device  rootfs  embedded  zah  linux  rm  ubuntu  sudo  sudoers  nopasswd  visudo  udev  key  gpg  sign  ip  ss  network  netstat  snap  deploy  ssh  systemd  socat  networking  serial  udp  tc  mtu  select  robotics  kalman_filter  kalman  filter  control  code  extensions  json  yaml  schema  dev container  yocto  poky  projects  courses to follow  world  gazebo_ros2_control  position_controller  effort_controller  velocity_controller  gazebo_ros_force  gazebo_ros_joint_state_publisher  joint_state_publisher  vrx  buoyancy 

cross compiler hello

Install ARM cross-compiler on ubuntu machine and use it's for hello world


A cross compiler is a compiler capable of creating executable code for a platform other than the one on which the compiler is running (wikipedia)

install cross compiler#

install crosscompiler tools
sudo apt install crossbuild-essential-arm64

toolchain setting file#

aarch64-linux-gnu-toolchain.cmake
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR "aarch64")
set(CMAKE_C_COMPILER aarch64-linux-gnu-gcc)
set(CMAKE_CXX_COMPILER aarch64-linux-gnu-g++)
set(CMAKE_CUDA_COMPILER nvcc)
set(CMAKE_CUDA_HOST_COMPILER aarch64-linux-gnu-gcc)
set(CMAKE_FIND_ROOT_PATH "/usr/aarch64-linux-gnu")

set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)

demo#

├── aarch64-linux-gnu-toolchain.cmake
├── build
├── CMakeLists.txt
└── src
    └── hello.cpp

code#

#include <iostream>

int main(){
    std::cout << "hello cross compiler" << std::endl;
    return 0;
}
cmake_minimum_required(VERSION 3.15)
# Toolchain settings
set(CMAKE_TOOLCHAIN_FILE aarch64-linux-gnu-toolchain.cmake)

project(CrossCompiler_demo)

add_executable(hello_cc src/hello.cpp)

Warning

It is crucial to set the value of CMAKE_TOOLCHAIN_FILE before project() is invoked, because project() triggers toolchain detection and verification.


cmake gui#

  • using cmake gui
  • set cross compiler settings from file

make, check, run#

make#

  • Run make from build folder
  • Check executable arch with file command
  • Run with qemu or Copy to embedded device

check#

cd build
# Result
file hello_cc 
hello_cc: ELF 64-bit LSB shared object, ARM aarch64, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-aarch64.so.1, BuildID[sha1]=5425e3fd790ba1a6a07c4963f0606a58edf53aa7, for GNU/Linux 3.7.0, not stripped

run#

Run ARM binary using qemu

sudo apt-get install qemu-user-static
# from build folder
qemu-arm-static -L /usr/arm-linux-gnueabihf ./hello_cc

Ref#